﻿using LinFu.AOP.Interfaces;

namespace BrainTechLLC
{
	public class ObservableMethodWrapper : AroundMethodBase, IAroundInvoke
	{
		protected override void Execute(IInvocationContext context, CutpointType when, object returnValue)
		{
			object thisObject = context.Target;
			ObservableMethodAttribute[] attrs = context.TargetMethod.ReadAttribute<ObservableMethodAttribute>();

			if (when == CutpointType.Before)
				attrs.ForEachAttribute(attr => attr.DoWorkBefore(context, thisObject));
			else
				attrs.ForEachAttribute(attr => attr.DoWorkAfter(context, thisObject, returnValue));
		}
	}
}

